import { NodeSize } from '../config'

export default function unique(flow) {
  flow.register('Unique', ({ PolygonNode, PolygonNodeModel, h }) => {
    class Node extends PolygonNode {
      getIconShape() {
        return h(
          'svg',
          {
            width: NodeSize,
            height: NodeSize,
            viewBox: '0 0 1024 1024'
          },
          h(
            'path',
            {
              fill: '#3D6480',
              d: 'M907.971048 492.665905v-3.072l-3.169524-0.048762-55.515429-54.905905-17.139809 17.334857 37.351619 36.937143c-187.684571-7.070476-235.032381-71.631238-235.032381-294.009905V76.824381H93.159619v180.175238h501.321143c0.902095 17.529905 2.364952 34.06019 4.315428 49.883429H93.159619v180.199619h541.305905v-61.17181c25.088 42.422857 64.170667 71.777524 123.977143 88.478476-55.296 21.918476-96.49981 58.465524-123.977143 109.909334v-87.356953H93.159619v180.199619H602.697143a489.130667 489.130667 0 0 0-7.119238 49.883429H93.159619v180.175238h541.305905v-121.441524c0-190.488381 73.728-282.282667 237.787428-293.497905l-40.106666 39.643429 17.139809 17.334857 78.165334-77.312-19.480381-19.260952z m-314.953143-47.030857H134.607238v-97.328762h458.410667v97.328762z m6.534095-240.810667h-6.534095v10.727619H134.607238v-10.727619h-5.534476V169.20381h5.534476V118.247619h458.410667v50.956191h6.534095v35.620571z m-6.534095 470.893714H134.607238v-97.328762h458.410667v97.328762z m6.534095 219.331048h-6.534095v10.703238H134.607238v-10.703238h-5.534476V859.428571h5.534476v-50.980571h458.410667v50.980571h6.534095v35.620572z'
            }
          ),
          h(
            'path',
            {
              fill: '#EFF9FE',
              d: 'M551.18019 169.20381h41.813334V118.247619H134.607238v50.956191h42.788572v35.620571H134.607238v10.727619h458.410667v-10.727619h-41.813334V169.20381zM229.888 166.424381H181.49181V130.80381h48.371809v35.620571z m53.052952 38.4H234.593524V169.20381h48.347428v35.620571z m52.687238-38.4h-48.347428V130.80381h48.347428v35.620571z m52.882286 38.4H340.114286V169.20381h48.371809v35.620571z m52.857905-38.4h-48.37181V130.80381h48.37181v35.620571z m52.662857 38.4h-48.371809V169.20381h48.371809v35.620571z m53.052952-38.4h-48.347428V130.80381h48.347428v35.620571z'
            }
          ),
          h(
            'path',
            {
              fill: '#EC0800',
              d: 'M287.256381 130.80381h48.347429v35.620571h-48.347429zM181.49181 130.80381h48.371809v35.620571H181.49181zM392.97219 130.80381h48.37181v35.620571h-48.37181zM234.593524 169.20381h48.347428v35.620571H234.593524zM177.39581 169.20381H129.072762v35.620571h48.323048zM340.114286 169.20381h48.371809v35.620571H340.114286zM498.736762 130.80381h48.347428v35.620571h-48.347428zM445.635048 169.20381h48.371809v35.620571h-48.371809zM551.18019 169.20381v35.620571h48.37181V169.20381h-6.534095z'
            }
          ),
          h(
            'path',
            {
              fill: '#EFF9FE',
              d: 'M551.18019 859.428571h41.813334v-50.980571H134.607238v50.980571h42.788572v35.620572H134.607238v10.703238h458.410667v-10.703238h-41.813334V859.428571z m-321.29219-2.779428H181.49181v-35.620572h48.371809v35.620572z m53.052952 38.4H234.593524V859.428571h48.347428v35.620572z m52.687238-38.4h-48.347428v-35.620572h48.347428v35.620572z m52.882286 38.4H340.114286V859.428571h48.371809v35.620572z m52.857905-38.4h-48.37181v-35.620572h48.37181v35.620572z m52.662857 38.4h-48.371809V859.428571h48.371809v35.620572z m53.052952-38.4h-48.347428v-35.620572h48.347428v35.620572z'
            }
          ),
          h(
            'path',
            {
              fill: '#EC0800',
              d: 'M287.256381 821.028571h48.347429v35.620572h-48.347429zM181.49181 821.028571h48.371809v35.620572H181.49181zM392.97219 821.028571h48.37181v35.620572h-48.37181zM234.593524 859.428571h48.347428v35.620572H234.593524zM177.39581 859.428571H129.072762v35.620572h48.323048zM340.114286 859.428571h48.371809v35.620572H340.114286zM498.736762 821.028571h48.347428v35.620572h-48.347428zM445.635048 859.428571h48.371809v35.620572h-48.371809zM551.18019 859.428571v35.620572h48.37181V859.428571h-6.534095z'
            }
          ),
          h(
            'path',
            {
              fill: '#EFF9FE',
              d: 'M134.607238 348.306286h458.410667v97.328762H134.607238zM134.607238 578.389333h458.410667v97.328762H134.607238z'
            }
          )
        )
      }

      getLabelShape() {
        return h(
          'text',
          {
            fill: '#000000',
            fontSize: 12,
            x: NodeSize / 2,
            y: NodeSize + 20,
            textAnchor: 'middle',
            dominantBaseline: 'middle'
          },
          '去除重复记录'
        )
      }

      getShape() {
        const { x, y, width, height } = this.getAttributes()
        const transform = `matrix(1 0 0 1 ${x - width / 2} ${y - height / 2})`
        return h(
          'g',
          {
            transform
          },
          [
            h(
              'rect',
              {
                rx: 5,
                ry: 5,
                width: NodeSize,
                height: NodeSize,
                fill: '#fff',
                stroke: '#3D6380',
                strokeWidth: 1
              }
            ),
            this.getIconShape(),
            this.getLabelShape()
          ]
        )
      }
    }
    class Model extends PolygonNodeModel {
      constructor(data, graphModel) {
        super(data, graphModel)
        this.points = [
          [NodeSize / 2, 0],
          [NodeSize, NodeSize / 2],
          [NodeSize / 2, NodeSize],
          [0, NodeSize / 2]
        ]
      }
    }

    return {
      view: Node,
      model: Model
    }
  })
}
